package cn.tedu.review;

import java.util.Scanner;

/**本类用于复习单例模式之饿汉式*/
public class Singleton1 {
    public static void main(String[] args) {
        MySingle1 s1 = MySingle1.getSingle1();
        MySingle1 s2 = MySingle1.getSingle1();
        System.out.println(s1==s2);

        MySingle2 s3 = MySingle2.getSingle2();
        MySingle2 s4 = MySingle2.getSingle2();
        System.out.println(s3==s4);
    }
}
class MySingle1{
    private MySingle1(){}
    private static MySingle1 single1 = new MySingle1();
    public static MySingle1 getSingle1 (){
        return single1;
    }
}
/**单例模式-懒汉式*/
class MySingle2{
    private MySingle2(){}
    private static MySingle2 single2;
    public static MySingle2 getSingle2(){
        if (single2==null)
            single2 = new MySingle2();
        return single2;
    }
}
